/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aqu.controlador.CuentasPorPagar;

import aqu.bean.generico.BeanGenerico;
import aqu.persistencia.Dao.CuentasPorPagar.CxpTipoNotaManager;
import aqu.persistencia.entity.CxpTipoNota;
import aqu.persistencia.utilidad.MessagesController;
import com.icesoft.faces.component.ext.RowSelectorEvent;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;

/**
 *
 * @author Verito Ramirez
 *         Victor Jaramillo
 */
@ManagedBean(name = "tipoNotaController")
@ViewScoped
public class TipoNotaController extends BeanGenerico {

    private CxpTipoNota tipoNota;
    private List<CxpTipoNota> lista;
    private CxpTipoNotaManager cxpTipoNotaManager = new CxpTipoNotaManager();
    private boolean panelvisible;

    public TipoNotaController() {

        tipoNota = new CxpTipoNota();
        lista = cxpTipoNotaManager.getList();
    }

    public boolean isPanelvisible() {
        return panelvisible;
    }

    public void setPanelvisible(boolean panelvisible) {
        this.panelvisible = panelvisible;
    }

    public void llamarPanelvisible(ActionEvent event) {
        panelvisible = !panelvisible;
    }

    public List<CxpTipoNota> getLista() {
        lista = cxpTipoNotaManager.getList();
        return lista;
    }

    public void setLista(List<CxpTipoNota> lista) {
        this.lista = lista;
    }
    
   

    public void nuevo(ActionEvent actionEvent) {
        tipoNota = new CxpTipoNota();
    }

    public String eliminar() {
        try {
            CxpTipoNota tipoNotaTemp = (CxpTipoNota) (tipoNota);
            if (cxpTipoNotaManager.delete(tipoNotaTemp) == false) {
                llamarPanelvisible(null);
            }
            tipoNota=new CxpTipoNota();
        } catch (Exception e) {
            MessagesController.addInfo("Mensaje de error :", e.getMessage());
            llamarPanelvisible(null);
        }

        return "index";

    }

    public void insertar(ActionEvent actionEvent) {
        try {
            tipoNota.setCxpCodigoTipNot(MessagesController.obtenerkeyautomaticosinceros("cxp_tiponota", "CXP_CODIGO_TIPNOT"));
            if (cxpTipoNotaManager.create(tipoNota) == false) {
                llamarPanelvisible(null);
            }
            tipoNota=new CxpTipoNota();
        } catch (Exception e) {
            MessagesController.addInfo("Mensaje de error :", e.getMessage());
            llamarPanelvisible(null);
        }

    }

    public void modificar(ActionEvent actionEvent) {
        try {
            if (cxpTipoNotaManager.update(tipoNota) == false) {
                llamarPanelvisible(null);

            }
        } catch (Exception e) {
            MessagesController.addInfo("Mensaje de error :", e.getMessage());
            llamarPanelvisible(null);
        }


    }

    public void rowSelectionListener(RowSelectorEvent event) {
        tipoNota = lista.get(event.getRow());
    }

    public CxpTipoNotaManager getCxpTipoNotaManager() {
        return cxpTipoNotaManager;        
    }

    public void setCxpTipoNotaManager(CxpTipoNotaManager cxpTipoNotaManager) {
        this.cxpTipoNotaManager = cxpTipoNotaManager;
    }

    public CxpTipoNota getTipoNota() {
        return tipoNota;
    }

    public void setTipoNota(CxpTipoNota tipoNota) {
        this.tipoNota = tipoNota;
    }
    
}